Thread: [plz help]confusion about comparison between two strings to me

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    My guess is that there is a stray '\r' in there which might be why it is different on windows and linux. A carriage return will cause the cursor to go to the start of the line, which would be why the "<--" is at the start of the line instead of after the string.

    How are you reading the data into the Database array? That's likely where the problem (or at least the solution) is.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by kyaky View Post
    where the hell is "s]" from.......... i am nearly crazy... 5:30am...
    You are probably printing back-spaces or some other "move the cursor" characters that happen to be the rubbish in some un-initialized variable - that would be my theory at least.

    --
    Mats

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    When you read a file in text mode, the carriage returns and linefeeds are automatically converted to a single character: '\n'. In binary mode that doesn't happen, though, so you may get different behavior depending on your platform.

    Did you edit the file that has the records by hand (i.e. in an editor outside of your code)?

  4. #19
    Registered User
    Join Date
    Aug 2007
    Posts
    23
    the txt is that:
    Code:
    001.645.2
    Learning C++
    Gregory	Harrison
    1
    001.721.3
    C++ for Beginners
    Quentin	Resnick
    2
    25 9 1999
    Me
    001.384.2
    C++ Tools
    Kieren Legrande
    1
    the reading is:
    Code:
    while(!InData.eof())
                {
    		InData.getline(Database[NumBooks].CallNumber,MaxCallNumber+1,'\n');
            	InData.getline(Database[NumBooks].Title,MaxTitle,'\n');
                    InData.getline(Database[NumBooks].Author,MaxAuthor,'\n');	
                    InData.getline(Database[NumBooks].BookStatus,MaxBookStatus,'\n');
    
                    if (Database[NumBooks].BookStatus[0]=='2')
            		{
                        InData.getline(Database[NumBooks].DueDate,MaxDueDate);
                        for (int i = 0; i < MaxDueDate; i++)
                        {
                            if (Database[NumBooks].DueDate[i] == ' ')
                                Database[NumBooks].DueDate[i] = '/';
                        }
                        
                        InData.getline(Database[NumBooks].BorrowersName,MaxBorrowersName,'\n');
                    }
                    else
                    {
                        strcpy(Database[NumBooks].DueDate,"N/A");
                        strcpy(Database[NumBooks].BorrowersName,"N/A"); 
                    }
                    NumBooks++;
                }
                InData.close();
                cout << "Txt file was successfully loaded!" << endl;
    i think the reading has problem... but i dunno how to read... was i right to write like that?

  5. #20
    Registered User
    Join Date
    Aug 2007
    Posts
    23
    Finally!!!! i found where the problem was... such a stupid i made again... the txt file has something wrong... because i made this txt file in windows it has 0D(CR) in this file... it made me crazy!!! i will be my biggest lesson in my life up to now... thank you alot... i love you guys!!!!!

  6. #21
    Registered User
    Join Date
    Aug 2007
    Posts
    23
    6:15 am ... i can go to bed finally!!!!! OMG!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  3. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  4. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM